package bepviet.android.ui.fragment;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import bepviet.android.engine.R;
import bepviet.android.ui.PreparedMail;

public class SendMailFragment {
	private TextView txtback,mailcontent,mailaddress,mailsubject;
	private Button btnsend;	
	private Activity mParent;
	
	public SendMailFragment(Activity parent){
		this.mParent = parent;
	}
	
	public void setMailContent(String content) {
		
	}
	
	public View getView(){
		View view = LayoutInflater.from(this.mParent).inflate(R.layout.preparedmail, null);
		txtback = (TextView)view.findViewById(R.id.txtback_mail);
		mailcontent =(TextView)view.findViewById(R.id.mailcontent);
		mailaddress =(TextView)view.findViewById(R.id.mailaddress);
		mailsubject =(TextView)view.findViewById(R.id.mailsubject);
		btnsend = (Button)view.findViewById(R.id.btnsend);
//		Bundle bundle = getIntent().getExtras();	
//		mailcontent.setText(bundle.getString("contentmail")); // get from mail content
		txtback.setOnClickListener(new View.OnClickListener() {			
			@Override
			public void onClick(View v) {
				mParent.finish();	
				Toast.makeText(mParent, "fffffffffff", Toast.LENGTH_LONG).show();
			}
		});
		
		btnsend.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {		
				Toast.makeText(mParent, "fffffffffff", Toast.LENGTH_LONG).show();
				
				Intent intent = new Intent(Intent.ACTION_SEND); 
            	intent.setType("plain/text"); //use this line for testing in the emulator 
            	intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            	//i.setType("message/rfc822") ; // use from live device
            	intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{mailaddress.getText().toString()}); 
            	intent.putExtra(android.content.Intent.EXTRA_SUBJECT,mailsubject.getText()); 
            	intent.putExtra(android.content.Intent.EXTRA_TEXT, mailcontent.getText()); 
            	mParent.startActivity(Intent.createChooser(intent, "Select email application."));
			}
		});
		
		LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
		view.setLayoutParams(params);
		return view;
	}
}
